<template>
  <div class="_wz_cent_main _wz_sendNotice">
    <Card :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="通知标题">
          <i-input v-model="formDataSearch.noticeTitle" placeholder="通知标题搜索" clearable />
        </FormItem>
        <FormItem label="回复状态">
          <i-select v-model.number="formDataSearch.noticeReplyType" filterable placeholder="请选择回复状态" clearable>
            <Option :value="0">无需回复</Option>
            <Option :value="1">需要回复</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="noticeAdd">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>

    <!--    添加-->
    <Drawer :title="noticeAddTitle" v-model="noticeAddType" width="720" :draggable="true" :mask-closable="false" :styles="formOperationStyles">
      <sendNoticeAdd v-if="noticeAddType" @closeFun="closeFun" :selectData="selectData"></sendNoticeAdd>
    </Drawer>
    <!--    查看-->
    <Drawer title="查看" v-model="noticeSeeType" width="800" :draggable="true" :mask-closable="false">
      <sendNoticeSee v-if="noticeSeeType" :selectData="selectData"></sendNoticeSee>
    </Drawer>
    <!--    阅读-->
    <Drawer title="阅读情况" v-model="readingType" width="1000" :draggable="true">
      <reading v-if="readingType" :selectData="selectData"></reading>
    </Drawer>
    <!--    查看附件-->
    <Drawer v-model="modal" title="通知附件查看" width="700" :draggable="true">
      <materialVideo v-if="modal && materialType==1" :materialData="materialData"></materialVideo>
      <materialIframe v-else-if="modal && materialType==5" :materialData="materialData"></materialIframe>
    </Drawer>
    <Spin size="large" fix v-if="spinShow"></Spin>

  </div>
</template>
<script>

import sendNoticeAdd from './sendNoticeAdd.vue'
import sendNoticeSee from './sendNoticeSee.vue'
  import materialIframe from '../public/materialIframe.vue'
  import materialVideo from '../public/materialVideo.vue'
  import reading from './reading.vue'
  import wzTbale from "../../../components/table/table";

  export default {
    components: {
      materialIframe,//文档
      sendNoticeAdd,//
      materialVideo,//视频
      reading,//阅读情况
      wzTbale,//列表
      sendNoticeSee,//查看
    },
    data() {
      return {
        noticeSeeType:false,//查看
        subDeptList:[],
        searchType:false,//搜索条件
        spinShow:false,//本页加载
        materialType:0,// 1 视频  5 文档
        readingType: false,//阅读情况
        noticeUserListType: 0,//0 企业 1 员工  发布通知类型
        modal: false,//弹出层状态
        materialData: null,
        selectData: {},
        noticeAddTitle: "",
        noticeAddType: false,
        formOperationStyles: {//表单左侧移出css
          height: 'calc(100% - 55px)',
          overflow: 'auto',
          paddingBottom: '53px',
          position: 'static'
        },
        formDataSearch: {},//搜索表单数据


        tableData: {
          url: this.apiUrl.webApi + "/notice/deptMessage/noticeDeptMessagePageList",//请求地址
          method: 'post',//请求方式
          where: {},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 80, align: 'center', title: '序号'},
            {title: '通知标题', key: 'noticeTitle', minWidth: 200,},
            {
              title: '通知等级', key: 'noticeLvName', minWidth: 140,
              render: (h, params) => {
                var test = '';
                // 通知消息等级：1：普通，2：重要，3：紧急
                if (params.row.noticeLv == 1) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'success'
                    }
                  }, '普通')
                } else if (params.row.noticeLv == 2) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'warning'
                    }
                  }, '重要')
                } else {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'error'
                    }
                  }, '紧急')
                }
                return test;
              }
            },
            {
              title: '发布状态', key: 'noticeReleaseState', minWidth: 130,
              render: (h, params) => {
                return h('Tag', {
                  props: {type: 'dot', color: params.row.noticeReleaseState === 0 ? 'warning' : 'primary'}
                }, params.row.noticeReleaseState === 0 ? '未发布' : '已发布');
              }
            },
            {
              title: '签收情况', minWidth: 120, render: (h, params) => {
                return h('span', params.row.noticeReadNumber + "/" + params.row.noticeAllNumber+'人');
              }
            },
            {
              title: '回复情况', minWidth: 140, render: (h, params) => {
                if (!!!params.row.noticeReplyType || params.row.noticeReplyType === 0) {
                  return h('Tag', { props: {type: 'dot', color: 'success'}}, '无需回复');
                } else {
                  return h('span', params.row.noticeReplyNumber + "/" + params.row.noticeAllNumber+'人');
                }
              }
            },
            {title: '创建时间', key: 'createTime', minWidth: 180},
            {title: '运输企业', key: 'deptName', minWidth: 260,},
            {
              title: '操作', width: 120, fixed: 'right',
              render: (h, params) => {
                let operationButtons = [];


                //查看
                if (operationButtons.length > 0) {
                  operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                }
                operationButtons.push(h('span', {
                  style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.noticeSeeType = true;
                      // window.open(this.apiUrl.imgUrl+params.row.noticeFileUrl);
                    }
                  }
                }, '查看'))
                // //查看附件
                // if(!!params.row.noticeFileType){
                //
                // }


                var buttonList = [];

                //发布通知
                if (params.row.noticeReleaseState != 1) {
                  buttonList.push(h('DropdownItem', {
                    nativeOn: {
                      click: () => {
                        this.noticeReleaseFun(params.row);
                      }
                    }
                  }, '发布'))
                }

                //阅读情况
                if (params.row.noticeReleaseState == 1) {
                  buttonList.push(h('DropdownItem', {
                    nativeOn: {
                      click: () => {
                        this.selectData = JSON.parse(JSON.stringify(params.row))
                        this.readingType = true;
                      }
                    }
                  }, '阅读情况'))
                }


                //修改
                if (params.row.noticeReleaseState != 1 ) {
                  buttonList.push(h('DropdownItem', {
                    nativeOn: {
                      click: () => {
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.noticeAddType = true;
                      }
                    }
                  }, '修改'))
                }


                //删除
                buttonList.push(h('DropdownItem', {
                  nativeOn: {
                    click: () => {
                      this.noticeRem(params.row);
                    }
                  }
                }, '删除'))

                if (buttonList.length > 0) {
                  if (operationButtons.length > 0) {
                    operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                  }
                  operationButtons.push(h('Dropdown', {props: {trigger: "hover", transfer: true}},
                    [
                      h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"}}, '更多▼'),
                      h('DropdownMenu', {slot: "list"}, buttonList)
                    ])
                  )
                }
                return operationButtons;
              }
            },
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态
    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;


      //运输企业
      that.axios.post(that.apiUrl.coreDeptCoreDeptList, {}).then(res => {
        if (!!res) {
          that.subDeptList = res.data.data;
        }
      }).catch(err => {
        console.log("失败", err)
      })
    },
    methods: {//执行的方法
      //添加
      noticeAdd() {
        let that = this;
        that.selectData = {};
        that.noticeAddTitle = '添加';
        that.noticeAddType = true;
      },
      //添加修改触发后关闭刷新
      closeFun(data) {
        if (data) {//添加修改 刷新表单
          this.$refs.wzTbale.tableLoadData();
        }
        this.noticeAddType = false;
      },
      //删除通知
      noticeRem(data) {
        let that = this;
        that.$Modal.confirm({
          title: '删除提醒',
          content: '确定要删除选中的记录？',
          onOk: () => {
            that.tableLoading = true;//加载
            that.axios.post(that.apiUrl.webApi + "/notice/deptMessage/noticeDeptMessageDelete", {noticeUuid: data.uuid}).then(res => {
              that.tableLoading = false;//加载
              if (!!res) {
                that.$Message.success('数据删除成功');
                that.$refs.wzTbale.tableLoadData();
              }
            }).catch(err => {
              console.log('失败', err);
            })
          },
          onCancel: () => {
            //点击取消
          }
        });
      },
      //发布通知
      noticeReleaseFun(data) {
        let that = this;
        that.$Modal.confirm({
          title: '发布提醒',
          content: '确定要发布选中的通知吗?已经发布,不可以修改删除操作',
          okText: '发布',
          cancelText: '修改',
          onOk: () => {
            that.spinShow = true;
            that.axios.post(that.apiUrl.webApi + "/notice/deptMessage/noticeDeptMessageRelease", {noticeUuid: data.uuid}).then(res => {
              that.spinShow = false;
              if (!!res) {
                that.$Message.success('发布成功');
                that.$refs.wzTbale.tableLoadData();
              }
            }).catch(err => {
              console.log('失败', err);
            })
          },
          onCancel: () => {
            //取消 修改
            that.selectData = JSON.parse(JSON.stringify(data));
            that.noticeAddType = true;
          }
        });
      },
      //搜索
      searchSubmit() {//搜索
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },

    },
    watch: {//监听

    },
    props: {//接收来自父组件的数据

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>


<style lang="less">
  ._wz_sendNotice {
    height: 100%;
    display: flex;
    flex-direction: column;


  }
</style>
